import { createModel } from '@rematch/core';

import { RootModel } from '.';

type UserState = {
  /** 登录信息 */
  token?: string;
  /** 用户信息 */
  nickname?: string; // 昵称
  age?: number; // 年龄
  signature?: string; // 签名
  phone?: string; // 手机号
  email?: string; // 邮箱
  gender?: number; // 性别
  avatar?: string; // 头像
  /** 权限信息 */
  accesses?: string[]; // 拥有的权限
  groups?: string[]; // 属于的分组
};

export const user = createModel<RootModel>()({
  state: {
    nickname: 'xyx',
  } as UserState,
  reducers: {
    setToken(state, token: string) {
      return {
        ...state,
        token,
      };
    },
    setUserInfo(state, payload: Record<string, any>) {
      return {
        ...state,
        ...payload,
      };
    },
  },
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
  effects: _dispatch => ({}),
});
